var pageIndex = 1
var pageSize = 6

var app = new Vue({
  el: '#userInfo',
  data: {
    ulist: getUsersInfo(),
    plist: getUserPagin(pageIndex, pageSize),
    //ilist: getUserById()
  },
  methods: {
    deleteUsersById(index) {
      layer.confirm('确认要删除吗？', function () {
        $.getJSON(
          'http://47.102.45.219:8080/Appoint/editUserServlet/deleteUserById', {
            "id": index
          },
          function (data) {
            if (data.statu == 1) {

              //发异步删除数据
              //app.plist = getUserPagin(pageIndex, pageSize)
              xadmin.father_reload();
              layer.msg('已删除!', {
                icon: 1,
                time: 1000
              });

            } else {
              layer.msg('删除失败!', {
                icon: 0,
                time: 1000
              });
            }
          }
        )
      });
    },
    update(id) {

      xadmin.open('编辑', 'member-edit.html?id=' + id, 600, 400);

      //xadmin.close('member-edit.html')
      // editUsersById();
      // getUserById(id)
    },
    pwd(id) {
      xadmin.open('修改密码', 'member-password.html?id=' + id, 600, 400)
    }


    // $.ajax({
    //   url: "http://localhost:8080/Appoint/editUserServlet/editUser",
    //   data: $("form").serialize(),
    //   dataType: "json",
    //   async: false,
    //   success: function (data) {
    //     if (data.statu > 0) {
    //       app.ulist = getUsersInfo()
    //       layer.msg("修改成功")
    //     } else {
    //       layer.msg("修改失败")
    //     }
    //   }

    // })
  }

})

//获取user表信息
function getUsersInfo() {
  var list
  $.ajax({
    url: 'http://47.102.45.219:8080/Appoint/editUserServlet/getUserAll',
    dataType: 'json',
    async: false,
    success: function (data) {
      if (data.statu != 0) {
        list = data.data
        //var count = list.length

      } else {
        alert(data.msg)
      }
    }
  })
  return list
}



//分页查询user表
function getUserPagin(pageIndex, pageSize) {
  var listpagin
  $.ajax({
    url: "http://47.102.45.219:8080/Appoint/editUserServlet/getUsersPagin",
    data: {
      "pageIndex": pageIndex,
      "pageSize": pageSize
    },
    dataType: 'json',
    async: false,
    success: function (data) {
      if (data.statu != 0) {
        listpagin = data.data
        //alert(listpagin)
      } else {
        alert(data.msg)
      }
    }
  })
  return listpagin
}

//编辑信息
function editUsersById(id) {
  alert(5541477)
  $.post("http://47.102.45.219:8080/Appoint/editUserServlet/editUser", $("form").serialize(), function (data) {
    if (data.statu > 0) {
      app.ulist = getUsersInfo()
      layer.msg("修改成功")
    } else {
      layer.msg("修改失败")
    }
  })
}


//根据id获取user信息
function getUserById() {
  //alert(122)
  // alert(id)
  var list
  $.ajax({
    url: 'http://47.102.45.219:8080/Appoint/editUserServlet/getUserById',
    data: {
      "id": id
    },
    dataType: 'json',
    async: false,
    success: function (data) {
      if (data.statu != 0) {
        list = data.data
        //var count = list.length
        //alert(list)

      } else {
        alert(data.msg)
      }
    }
  })
  return list

}